Operations

T provides a simple mechanism for programming in what has come to be known as the object-oriented style of programming. Object-oriented style may be contrasted to what will here be called procedural style. In object-oriented programming, programs are organized by giving the behavior of objects when various operations are applied to them, whereas in procedural style, programs are organized by giving the behavior of procedures when applied to various kinds of objects. These styles are equivalent in terms of computational power, but each offers different advantages in terms of readability and modularity.

T supports the object-oriented style with a special kind of procedure known as an operation, and with forms which permit one to create objects which exhibit certain behavior when a given operation is applied to them.

When an operation is called, the following sequence of events occurs:
 A handler is obtained for the object which was the operation's first argument. (Operations must always be called with at least one argument.)

 The operation asks the handler for a method which will handle the operation for the object.

 The handler either provides a method, or it indicates that the object is not prepared to handle the operation.

 If the handler provided a method, the method is invoked. If not, then the operation's default method, if any, is invoked. If the operation has no default method, then the effect of the call to the operation is undefined (and presumably an error condition is signalled).

In this way, an object's handler may determine how the operation is to be performed for the object - that is, which particular method is to be invoked as a result of invoking the operation.

Handlers map operations to methods. Many objects may have the same handler, or a handler may be idiosyncratic to a particular object. However, every object has a handler, so all objects participate in the generic operation dispatch protocol.



Subsections